package com.muyu.danmo.controller;


import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.core.web.page.TableDataInfo;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.danmo.domain.DanmoUserVisitors;
import com.muyu.danmo.service.IDanmoUserVisitorsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 访客Controller
 * 
 * @author yangle
 * @date 2024-11-15
 */
@RestController
@RequestMapping("/userVisitors")
public class DanmoUserVisitorsController extends BaseController
{
    @Autowired
    private IDanmoUserVisitorsService danmoUserVisitorsService;

    /**
     * 查询访客列表
     */
//    @RequiresPermissions("system:userVisitors:list")
    @GetMapping("/list")
    public Result<TableDataInfo<DanmoUserVisitors>> list(DanmoUserVisitors danmoUserVisitors)
    {
        startPage();
        List<DanmoUserVisitors> list = danmoUserVisitorsService.selectDanmoUserVisitorsList(danmoUserVisitors);
        return getDataTable(list);
    }

    /**
     * 导出访客列表
     */
//    @RequiresPermissions("system:userVisitors:export")
    @Log(title = "访客", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DanmoUserVisitors danmoUserVisitors)
    {
        List<DanmoUserVisitors> list = danmoUserVisitorsService.selectDanmoUserVisitorsList(danmoUserVisitors);
        ExcelUtil<DanmoUserVisitors> util = new ExcelUtil<DanmoUserVisitors>(DanmoUserVisitors.class);
        util.exportExcel(response, list, "访客数据");
    }

    /**
     * 获取访客详细信息
     */
//    @RequiresPermissions("system:userVisitors:query")
    @GetMapping(value = "/{visitorId}")
    public Result getInfo(@PathVariable("visitorId") Long visitorId)
    {
        return Result.success(danmoUserVisitorsService.selectDanmoUserVisitorsByVisitorId(visitorId));
    }

    /**
     * 新增访客
     */
//    @RequiresPermissions("system:userVisitors:add")
    @Log(title = "访客", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody DanmoUserVisitors danmoUserVisitors)
    {
        return danmoUserVisitorsService.insertDanmoUserVisitors(danmoUserVisitors);
    }

    /**
     * 修改访客
     */
//    @RequiresPermissions("system:userVisitors:edit")
    @Log(title = "访客", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody DanmoUserVisitors danmoUserVisitors)
    {
        return danmoUserVisitorsService.updateDanmoUserVisitors(danmoUserVisitors);
    }

    /**
     * 删除访客
     */
//    @RequiresPermissions("system:userVisitors:remove")
    @Log(title = "访客", businessType = BusinessType.DELETE)
	@DeleteMapping("/{visitorIds}")
    public Result remove(@PathVariable Long[] visitorIds)
    {
        return danmoUserVisitorsService.deleteDanmoUserVisitorsByVisitorIds(visitorIds);
    }

    /**
     * 查看自己的访客
     */
    @GetMapping("/danmoUserVisitorsUserId")
    public Result<List<DanmoUserVisitors>> danmoUserVisitorsUserId() {
        List<DanmoUserVisitors> list = danmoUserVisitorsService.selectDanmoUserList();
        if (list.size() == 0) {
            return Result.error("暂无粉丝");
        }
      return Result.success(list);
    }



}
